package com.example.arno.androidsmartbulter.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.example.arno.androidsmartbulter.MainActivity;
import com.example.arno.androidsmartbulter.R;
import com.example.arno.androidsmartbulter.utils.SharedUtil;
import com.example.arno.androidsmartbulter.utils.StaticClass;
import com.example.arno.androidsmartbulter.utils.UtilTools;


public class SplashActivity extends AppCompatActivity {

    private TextView tv_splash;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case StaticClass.HANDLER_SPLASH:
                    //判断程序是否是第一次运行
                    if (isFirst()) {
                        startActivity(new Intent(SplashActivity.this, GuideActivity.class));
                    } else {
                        startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    }
                    finish();
                    break;
            }
        }
    };

    /*
        * 1.延时2000ms
        * 2.判断程序是否第一次运行
        * 3.自定义字体
        * 4.Activity全屏主题
        * */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initView();
    }

    private void initView() {
        //延时2000ms
        handler.sendEmptyMessageDelayed(StaticClass.HANDLER_SPLASH, 2000);

        tv_splash = (TextView) findViewById(R.id.tv_splash);
        //设置字体
        UtilTools.setTypeFace(this, tv_splash);
    }

    private boolean isFirst() {
        boolean isFirst = SharedUtil.getBoolean(this, StaticClass.SHARE_IS_FIRST, true);
        if (isFirst) {
            SharedUtil.putBoolean(this, StaticClass.SHARE_IS_FIRST, false);
            //是第一次运行
            return true;
        } else {
            return false;
        }
    }
    //禁止返回键

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
    }
}
